import time
import random
import json
import subprocess

CONFIG_FILE = "config.json"

def load_config():
    with open(CONFIG_FILE, "r", encoding="utf-8") as f:
        return json.load(f)

def run_once():
    subprocess.run(["python", "proxy_launcher.py"])
    subprocess.run(["python", "track_runner.py"])

def main():
    config = load_config()
    max_exec = config.get("MAX_EXECUTIONS", 1)
    interval = config.get("TIME_INTERVAL_MINUTES", 1)
    count = 0

    while max_exec == 0 or count < max_exec:
        pass #print(f"\n🌀 第 {count + 1} 次任务开始")
        run_once()
        count += 1
        if max_exec != 0 and count >= max_exec:
            break
        delay_sec = random.randint(0, 59)
        pass #print(f"⏳ 等待 {interval} 分钟 + {delay_sec} 秒后开始下一轮...\n")
        time.sleep(interval * 60 + delay_sec)

if __name__ == "__main__":
    main()
